package com.rongke.lequ.ui.activity.presenter

import android.os.CountDownTimer
import com.rongke.baselibrary.base.BasePresenter
import com.rongke.baselibrary.network.BaseCallBack
import com.rongke.baselibrary.network.BaseResponse
import com.rongke.baselibrary.network.RetrofitHelper
import com.rongke.baselibrary.util.CommonUtil
import com.rongke.baselibrary.util.StringUtil
import com.rongke.lequ.network.api.UserApi
import com.rongke.lequ.network.response.LoginResponse
import com.rongke.lequ.ui.activity.LoginActivity
import com.rongke.lequ.ui.activity.SplashActivity
import retrofit2.Call
import retrofit2.Response

/**
 * Created by jh352160 on 2018/5/23.
 */
class LoginPresenter : BasePresenter<LoginActivity>(){
    /**
     * 登录
     */
    fun doLogin(phone: String, psw: String) {
        if (!checkInput(phone, psw)) {
            return
        }

        RetrofitHelper.getRetrofit().create(UserApi::class.java).phoneLogin(phone, psw, "").enqueue(
                object : BaseCallBack<BaseResponse<LoginResponse>>(mView) {
                    override fun onSuccess(call: Call<BaseResponse<LoginResponse>>, response: Response<BaseResponse<LoginResponse>>) {
                        if (response.body()!!.isSuccess) {
                            loginSuccess(response.body()!!.data)
                        } else {
                            CommonUtil.showToast(mContext,response.body()!!.msg)
                        }
                    }
                })
    }

    private fun checkInput(phone: String, psw: String): Boolean {
        if (StringUtil.isEmpty(phone)){
            CommonUtil.showToast(mContext,"请输入手机号码")
            return false
        }
        if (StringUtil.isEmpty(psw)){
            CommonUtil.showToast(mContext,"请输入密码")
            return false
        }
        return true
    }

    private fun loginSuccess(data: LoginResponse){

    }
}